package com.house.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.house.user.dao.UserDao;
import com.house.user.entity.User;
import com.house.user.entity.dto.UserQueryDTO;
import com.house.user.service.IUserService;

@Service
@Transactional
public class UserServiceImpl implements IUserService{

	@Autowired
	private UserDao userDao;
	
	@Override
	public void saveOrUpdate(User user) {
		// TODO Auto-generated method stub
		userDao.save(user);
	}
	@Override
	public void delete(User user) {
		// TODO Auto-generated method stub
		userDao.delete(user);
	}

	@Override
	public List<User> findAll() {
		// TODO Auto-generated method stub
		List<User> list = (List<User>) userDao.findAll();
		return list;
	}
	@Override
	public User findOne(Integer id) {
		// TODO Auto-generated method stub
		return userDao.findOne(id.longValue());
	}

	@Override
	public User findOneByUserCode(UserQueryDTO userQueryDTO) {
		// TODO Auto-generated method stub
		User user = userDao.findOne(UserQueryDTO.getSpecification(userQueryDTO));
		return user;
	}

}
